package com.qfedu.openapi.web.master.controller;

import com.github.pagehelper.PageInfo;
import com.qfedu.openapi.web.master.entity.Application;
import com.qfedu.openapi.web.master.service.ApplicationService;
import com.qfedu.openapi.web.master.vo.MessageVo;
import com.qfedu.openapi.web.master.vo.PageVo;
import com.qfedu.openapi.web.master.vo.TableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/application")
public class ApplicationController {

    @Autowired
    private ApplicationService applicationService;

    //展示界面
    @RequestMapping("/applicationuser")
    @ResponseBody
    public TableVo<Application> getAllApplicationUsers(PageVo pageVo, Application application){
        TableVo<Application> applicationTableVo = new TableVo<>();
        PageInfo<Application> pageInfo = applicationService.findAllApplicationUser(pageVo,application);
        applicationTableVo.setCode("0");
        applicationTableVo.setCount(pageInfo.getTotal());
        applicationTableVo.setMsg("ok");
        applicationTableVo.setData(pageInfo.getList());
        return applicationTableVo;
    }

    //增加
    @RequestMapping("/add")
    @ResponseBody
    public MessageVo addApplicationuser(Application application){
        Integer a=applicationService.addApplicationuser(application);
        MessageVo messageVo = new MessageVo();
        messageVo.setStatus(a==1?true:false);
        messageVo.setMessage(a==1?"success":"failed");
        messageVo.setData(application);
        return messageVo;
    }

    //删除
    @RequestMapping("/del")
    @ResponseBody
    public MessageVo delApplicationuser(Integer[] ids){
        Integer a=applicationService.delApplicationuser(ids);
        MessageVo messageVo = new MessageVo();
        messageVo.setStatus(a>0?true:false);
        messageVo.setMessage(a>0?"success":"failed");
        return messageVo;
    }

    //修改
    @RequestMapping("/update")
    @ResponseBody
    public MessageVo updateApplicationuser(Application application){
        Integer a=applicationService.updateApplicationuser(application);
        MessageVo messageVo = new MessageVo();
        messageVo.setStatus(a==1?true:false);
        messageVo.setMessage(a==1?"success":"failed");
        return messageVo;
    }
}
